<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" type="shortcut icon" th:href="@{/img/favicon.ico}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/css/global.css}"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
    <title>Echo - 我的帖子</title>
</head>
<body>
<div class="nk-container">
    <!--    头部-->
    <header class="bg-dark sticky-top" th:replace="index::header"></header>
    <!-- 内容 -->
    <div class="main">
        <div class="container">
            <!-- 选项 -->
            <!--            <div class="position-relative">-->
            <!--                <ul class="nav nav-tabs" th:replace="/site/profile::profiletab"></ul>-->
            <!--            </div>-->
            <!-- 我的帖子 -->
            <div class="mt-4">
                <h6><b class="square"></b> 帖子总数 (<i th:text="${page.total}"></i>)</h6>
                <ul class="list-unstyled mt-4 pl-3 pr-3">
                    <li class="border-bottom pb-3 mt-4" th:each="post:${page.records}">
                        <div class="font-size-16 text-info">
                            <a th:href="@{|/discuss/detail/${post.id}|}" class="text-info"
                               th:utext="${post.title}">文章标题</a>
                            <br>
                            <div class="text-right font-size-12 text-muted">
                                赞 <i class="mr-3" th:text="${post.likeCount}"></i>
                                评论 <i class="mr-3" th:text="${post.commentCount}"></i>
                                发布于 <b
                                    th:text="${T(com.qf.blog.commons.utils.DateTimeUtils).getRelativeTime(post.createTime)}"></b>
                            </div>
                        </div>
                    </li>
                </ul>
                <!--分页 -->
                <nav class="mt-5" th:if="${page.total>0}" th:fragment="pagination">
                    <ul class="pagination justify-content-center">
                        <li class="page-item" th:class="|page-item ${page.current==1? 'disabled':''}|">
                            <a class="page-link" th:onclick="'handleQuery({current:1})'">首页</a>
                        </li>
                        <li th:class="|page-item ${page.current==1?'disabled':''}|">
                            <a class="page-link" th:onclick="'handleQuery({current:'+${page.current-1}+'})'">上一页</a>
                        </li>
                        <!--numbers.sequence 生成一个 page.from 到 page.to 的连续整数数组-->
                        <li th:each="i:${#numbers.sequence(page.from,page.to)}"
                            th:class="|page-item ${i==page.current? 'active' : ''}|">
                            <a class="page-link" th:href="@{${page.path}(current=${i})}" th:text="${i}"></a>
                        </li>
                        <li th:class="|page-item ${page.current==page.pages ? 'disabled':''}|">
                            <a class="page-link" th:onclick="'handleQuery({current:'+${page.current+1}+'})'">下一页</a>
                        </li>
                        <li class="page-item" th:class="|page-item ${page.current==page.pages ? 'disabled':''}|">
                            <a class="page-link" th:onclick="'handleQuery({current:'+${page.pages}+'})'">末页</a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>

    <!-- 尾部 -->
    <!--    <footer class="bg-dark" th:replace="index::footer"></footer>-->
</div>

<script th:src="@{/js/jquery-3.1.0.min.js}"></script>
<script th:src="@{/js/popper.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<script th:src="@{/js/global.js}"></script>
<script th:src="@{/js/index.js}"></script>
<script th:inline="javascript">
    function handleQuery(newParams) {
        const params = {
            current: 1,
            keywords: $('input[name=keyword]').val() || "",
            orderBy: [[${page.orderBy}]] || "create_time",
            ...newParams
        }
        const path = [[${page.path}]]
        const urlParams = new URLSearchParams();
        Object.entries(params).forEach(([key, value]) => {
            urlParams.append(key, value)
        })
        location.href = `${path}?${urlParams.toString()}`
    };
</script>
</body>
</html>
